﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pakxel.Framework;
using System.Data.SqlClient;
using System.Diagnostics;

namespace Pakxel.SmartLogistic
{
     class MenuManager  :  IMenuManager
    {
         List<T001Menu> MMItems;
         List<T001Menu> SMItems;
         string iConnectionString;

         public MenuManager(string ConnectionString)
         {
             iConnectionString = ConnectionString;
         }

        public List<T001Menu> GetMenuOptionFor(string UserName)
        {
            using (SqlConnection sqlConnection = new SqlConnection(iConnectionString))
            {
                using (SqlCommand storedProcCommand = new SqlCommand("GetMenuOptionsFor", sqlConnection))
                {
                    storedProcCommand.CommandType = System.Data.CommandType.StoredProcedure;
                    storedProcCommand.Parameters.Add(new SqlParameter() { ParameterName = "@T002UserName", Value = UserName });
                    sqlConnection.Open();
                    using (SqlDataReader reader = storedProcCommand.ExecuteReader())
                    {
                        MMItems = new List<T001Menu>();
                        while (reader.Read())
                        {
                            MMItems.Add(new T001Menu() { T001Name = reader["T001Name"].ToString(), T001ParentName = reader["T001ParentName"].ToString(), T001Text = reader["T001Text"].ToString() });
                        }
                    }
                }
            }
            
            return MMItems;
        }

        public List<T001Menu> GetSubMenuOptionFor(string UserName, string ParentMenu)
        {
            using (SqlConnection sqlConnection = new SqlConnection(iConnectionString))
            {
                using (SqlCommand storedProcCommand = new SqlCommand("GetSubMenuOptionsFor", sqlConnection))
                {
                    storedProcCommand.CommandType = System.Data.CommandType.StoredProcedure;
                    storedProcCommand.Parameters.Add(new SqlParameter() { ParameterName = "@T002UserName", Value = UserName });
                    storedProcCommand.Parameters.Add(new SqlParameter() { ParameterName = "@T001ParentName", Value = ParentMenu });
                    sqlConnection.Open();
                    using (SqlDataReader reader = storedProcCommand.ExecuteReader())
                    {
                        SMItems = new List<T001Menu>();
                        while (reader.Read())
                        {
                            SMItems.Add(new T001Menu() { T001Name = reader["T001Name"].ToString(), T001ParentName = reader["T001ParentName"].ToString(), T001Text = reader["T001Text"].ToString() });
                        }
                    }
                }
            }
            return SMItems;
        }
    }
}
